﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SE560Multimedia.src;

namespace SE560Multimedia.pages
{
    public partial class WebForm5 : System.Web.UI.Page
    {
        private SessionManager sessionManager;

        protected void Page_Load(object sender, EventArgs e)
        {
            sessionManager = new SessionManager(Session);

            if (!IsPostBack)
            {
                ProjectDataSetTableAdapters.userTableAdapter usrTableAdapter =
                    new ProjectDataSetTableAdapters.userTableAdapter();

                ProjectDataSet.userDataTable usrDataTable =
                    usrTableAdapter.GetDataByUserID(sessionManager.SessionLoggedUserId);
                TextBoxUserNameSurname.Text =
                    (String)usrDataTable.Rows[0]["USER_NAME_SURNAME"];
                TextBoxSecurityQuestion.Text =
                    (String)usrDataTable.Rows[0]["USER_SECURITY_QUESTION"];
                TextBoxSecurityAnswer.Text =
                    (String)usrDataTable.Rows[0]["USER_SECURITY_ANSWER"];
                TextBoxPassword.Text =
                    (String)usrDataTable.Rows[0]["USER_PASSWORD"];
                TextBoxConfirmPassword.Text = TextBoxPassword.Text;
            }

        }

        protected void ChangeButton_Click(object sender, EventArgs e)
        {
            ProjectDataSetTableAdapters.userTableAdapter usrTableAdapter =
                new ProjectDataSetTableAdapters.userTableAdapter();
            usrTableAdapter.UpdateQuery(
                TextBoxPassword.Text, TextBoxUserNameSurname.Text,
                TextBoxSecurityQuestion.Text, TextBoxSecurityAnswer.Text,
                sessionManager.SessionLoggedUserId);
            sessionManager.SessionLoggedUserName = TextBoxUserNameSurname.Text;

            LabelOperationResult.Text = "User preferences has been changed";
        }
    }
}
